import math;

class File:
	def __init__(self, strtr):
		self.pos = 0;
		self.fd = open(strtr, "r");
		self.tokens = list();
	def nextToken(self):
		while (self.pos == len(self.tokens)):
			self.tokens = self.fd.readline().split();
			self.pos = 0;
		t = self.pos;
		self.pos += 1;	
		return self.tokens[t];

	def nextInt(self):
		return int(self.nextToken());

inf = File("plain.in");
ans = File("plain.out");

T = inf.nextInt();

sum = 0.0;

for i in range(T):
	n = inf.nextInt();
	m = inf.nextInt();
	res = 0;
	for i in range(n):
		for j in range(m):
			inf.nextInt();
	a = [[0 for  i in range(m)]for j in range(n)];
	for j in range(n):
		for k in range(m):
			a[j][k] = ans.nextInt();
	for j in range(n):
		for k in range(m):
			if j + 1 < n:
				res += 1 << abs(a[j][k] - a[j + 1][k]);
			if k + 1 < m:
				res += 1 << abs(a[j][k] - a[j][k + 1]);
	print("Partially result: " + str(math.log(res, 2)));
	sum += math.log(res, 2);

print("Cummulative result: " + str(sum / T));